import { signUpAction } from "@/app/actions";
import { FormMessage, Message } from "@/components/form-message";
import { SubmitButton } from "@/components/submit-button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import Link from "next/link";
import { SmtpMessage } from "../smtp-message";

export default async function Signup(props: {
  searchParams: Promise<Message>;
}) {
  const searchParams = await props.searchParams;
  if ("message" in searchParams) {
    return (
      <div className="w-full flex-1 flex items-center justify-center gap-2 p-4">
        <FormMessage message={searchParams} />
      </div>
    );
  }

  return (
    <>
      <form className="flex flex-col min-w-64 max-w-64 mx-auto">
        <h1 className="text-2xl font-medium text-white mb-2">注册</h1>
        <p className="text-sm text-white/70 mb-8">
          已有账户？{" "}
          <Link className="text-white font-medium underline hover:text-white/80" href="/sign-in">
            登录
          </Link>
        </p>
        <div className="flex flex-col gap-4">
          <div>
            <Label htmlFor="email" className="text-white mb-2 block">邮箱</Label>
            <Input 
              name="email" 
              placeholder="your@example.com" 
              required 
              className="bg-white/20 border-white/30 text-white placeholder-white/50 focus:border-white/50 focus:ring-white/30"
            />
          </div>
          <div>
            <Label htmlFor="password" className="text-white mb-2 block">密码</Label>
            <Input
              type="password"
              name="password"
              placeholder="您的密码"
              minLength={6}
              required
              className="bg-white/20 border-white/30 text-white placeholder-white/50 focus:border-white/50 focus:ring-white/30"
            />
          </div>
          <SubmitButton 
            formAction={signUpAction} 
            pendingText="注册中..."
            className="bg-white/20 hover:bg-white/30 text-white border-white/30 mt-4"
          >
            注册
          </SubmitButton>
          <FormMessage message={searchParams} />
        </div>
      </form>
      <SmtpMessage />
    </>
  );
}
